package com.base.chat.presenter;

import android.app.Activity;

import com.base.chat.bean.SearchFriendsBean;
import com.base.chat.view.SearchFriendsListView;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by zw
 */

public class SearchFriendsListPresenter extends BasePresenter<SearchFriendsListView>{
    public SearchFriendsListPresenter(SearchFriendsListView view, Activity activity) {
        super(view, activity);
    }

    public void getList(String key){
        mView.showPb();
        Map<String, Object> map = new HashMap<>();
        map.put("key",key);
        Disposable enqueue = RealNetWorkUtil.get().method("api-im/search/searchUser").params(map)
                .build().enqueue(SearchFriendsBean.class, new CallBackImpl<SearchFriendsBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb();
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(SearchFriendsBean list) {
                        mView.hidePb();
                            //刷新
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnList(list);
                            }else {
                                mView.returnNoData();
                            }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }
    public void addFriend(String id,String applyRecordType){
        mView.showPb();
        Map<String, Object> map = new HashMap<>();
        map.put("friendId",id);
        map.put("applyRecordType",applyRecordType);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-im/friend/addFriend").content(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb();
                        mView.showError();
                    }

                    @Override
                    public void onNext(String msg) {
                        mView.hidePb();
                        mView.returnAddFriendSuccess("请求已发送");

                    }
                });

        mCompositeDisposable.add(enqueue);
    }
}
